// adodb.h
#ifndef BSLIB_ADODB_H_
#define BSLIB_ADODB_H_

#include <cstddef>

class ADODB
{
public:
	enum CommandType
	{
		CommandText,
		CommandSP
	};

	enum ParameterDirection
	{
		ParameterInput,
		ParameterOutput,
		ParameterInputOutput
	};

	enum DataType
	{
		DataTinyInt,
		DataUnsignedTinyInt,
		DataSmallInt,
		DataUnsignedSmallInt,
		DataInt,
		DataUnsignedInt,
		DataBigInt,
		DataUnsignedBigInt,
		DataFloat,
		DataDouble,
		DataChar,
		DataVarChar,
		DataWChar,
		DataVarWChar,
		DataDateTime,
		DataSmallDateTime,
		DataTimeStamp,
		DataBinary
	};

	static const int NULL_DATA = -1;

	ADODB();
	~ADODB();

	bool Connect(const wchar_t* ip, const wchar_t* db, const wchar_t* user, const wchar_t* password, unsigned long timeout = 0);
	bool Connect(const wchar_t* connection_string, unsigned long timeout = 0);
	bool Disconnect();

	bool SetCommand(CommandType type, const wchar_t* sql);

	bool SetParameter(short column, ParameterDirection direction, DataType type, const void* data, std::size_t size);
	bool SetParameter(const wchar_t* column, ParameterDirection direction, DataType type, const void* data, std::size_t size);
	
	bool ExecuteCommand(HRESULT& hr, unsigned long timeout = 0);

	bool GetRowCount(unsigned long& count);
	bool GetRowSize(std::size_t& size);

	bool GetColumnCount(short& count);
	bool GetColumnType(short column, DataType& type);
	bool GetColumnType(const wchar_t* column, DataType& type);
	bool GetColumnActualSize(short column, std::size_t& size);
	bool GetColumnActualSize(const wchar_t* column, std::size_t& size);
	bool GetColumnDefinedSize(short column, std::size_t& size);
	bool GetColumnDefinedSize(const wchar_t* column, std::size_t& size);
	bool GetColumnData(short column, DataType type, void* buffer, std::size_t buffer_size, int* actual_size = NULL);
	bool GetColumnData(const wchar_t* column, DataType type, void* buffer, std::size_t buffer_size, int* actual_size = NULL);
		
	bool IsRowEmpty();
	bool MoveNextRow();
					
private:
	class Impl;
	Impl* impl_;
};

#endif // BSLIB_ADODB_H_